<template>
  <div>
     <van-nav-bar title="新增收货地址" fixed placeholder  left-arrow  @click-left="onClickLeft"/>

    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @change-detail="onChangeDetail"
    />
    

  </div>
</template>

<script>
import { Toast } from "vant";
import { addAddressApi } from "@/utils/api";
import { Dialog } from "vant";
// import { areaList } from "@vant/area-data";
export default {
  data() {
    return {
      areaList: {
        province_list: {
          110000: "北京市",
          120000: "天津市",
          130000: "浙江省"
        },
        city_list: {
          110100: "北京市",
          120100: "天津市",
          130100: "杭州市"
        },
        county_list: {
          110101: "东城区",
          110102: "西城区",
          130101: "上城区",
          130102: "拱墅区",
          130103: "西湖区"
        }
      },
      searchResult: []
    };
  },

  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    async onSave(content) {
      Toast("save");
      // console.log(content);
      // 添加用户信息
      let res = await addAddressApi({
        token: localStorage.getItem("token"),
        getName: content.name,
        getPhone: content.tel,
        address: content.addressDetail,
        status: content.isDefault ? 1 : 2
      });
      console.log(res);
      Dialog.alert({
        message: res.msg
      }).then(() => {
        this.$router.go(-1);
      });
    },
    // onDelete() {
    //   Toast("delete");
    // },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区"
          },
          {
            name: "旺田商务楼",
            address: "杭州上城区"
          }
        ];
      } else {
        this.searchResult = [];
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
